package com.swh.service.Impl;

import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.swh.dao.base.BaseDao;
import com.swh.service.BaseService;

import java.util.List;

/**
 * @Author: swh
 * @Description:
 * @Date: 2020/12/16 11:05
 * @Version: 1.0
 */
public class BaseServiceImpl<T> implements BaseService<T> {

    private BaseDao baseDao;

    public BaseServiceImpl(BaseDao dao) {
        this.baseDao = dao;
    }


    @Override
    public T findById(Integer id) {
        return (T) baseDao.load(id);
    }

    @Override
    public PageInfo<T> findPage(int pageNum, int pageSize) {
        PageHelper.startPage(pageNum, pageSize);
        List<T> list = baseDao.pageList((pageNum - 1) * pageSize, pageSize);
        return new PageInfo<>(list);
    }

    @Override
    public void insert(T obj) {
        baseDao.insert(obj);
    }


    @Override
    public void delete(Integer id) {
        baseDao.delete(id);
    }

    @Override
    public void update(T obj) {
        baseDao.update(obj);
    }
}
